﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class InputField_Beta : MonoBehaviour
{
    [SerializeField] GameObject Dog;
    [SerializeField] Rigidbody2D DogRig;
    [SerializeField] GameObject PickPos;
    [SerializeField] GameObject key;
    [SerializeField] GameObject why;
    [SerializeField] GameObject love;
    [SerializeField] GameObject Yes;
    [SerializeField] GameObject No;
    public bool ispicked = false;
    public InputField Instruction;
    public AudioSource DogBark;
    public Animator DogAnim;

    private void Update()
    {
        if(Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        if(Instruction.text == "")
        {
            why.SetActive(false);
            love.SetActive(false);
            Yes.SetActive(false);
            No.SetActive(false);
        }
       
            if (Input.GetKeyDown(KeyCode.Return))
        {
            if (Instruction.text == "go"|| Instruction.text == "walk"|| Instruction.text == "run")
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                DogAnim.SetBool("sitting", false);
                DogAnim.SetBool("going", true);
                this.transform.localScale = new Vector2(1, 1);
                DogRig.velocity = new Vector2(4, 0);
            }
            if (Instruction.text == "stop")
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                DogAnim.SetBool("going", false);
                DogRig.velocity = new Vector2(0, 0);
            }
            if (Instruction.text == "jump")
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                DogRig.velocity = new Vector2(0, 4);
            }
            if (Instruction.text == "back")
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                DogAnim.SetBool("sitting", false);
                DogAnim.SetBool("going", true);
                this.transform.localScale = new Vector2(-1, 1);
                DogRig.velocity = new Vector2(-5, 0);
            }
            if (Instruction.text == "bark")
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                DogAnim.SetBool("going", false);
                DogRig.velocity = new Vector2(0, 0);
                DogBark.Play();
            }
            if (Instruction.text == "pick up")
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                if (Vector2.Distance(Dog.transform.position, key.transform.position) <= 5)
                {
                    key.transform.parent = PickPos.transform;
                    key.transform.localPosition = new Vector3(0, 0, 0);
                    ispicked = true;
                }

            }

          
            if (Instruction.text == "sit")
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                DogAnim.SetBool("sitting", true);
            }
            if (Instruction.text == "i can't" || Instruction.text == "i cant"|| Instruction.text == "i can't acompany with you" 
                || Instruction.text == "i cant acompany with you"|| Instruction.text == "i'm dead" || Instruction.text == "i am dead")
            {
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                why.SetActive(true);
                why.transform.localScale = new Vector2(0.5f, 0.5f);
                if (this.transform.localScale.x == -1)
                {
                    why.transform.localScale = new Vector2(-0.5f, 0.5f);
                }
            }
            if (Instruction.text == "i love you" || Instruction.text == "thank you" || 
                Instruction.text == "goodbye"||Instruction.text == "bye"||Instruction.text == "byebye")
            {
                why.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(false);
                love.SetActive(true);
                love.transform.localScale = new Vector2(0.5f, 0.5f);
                if (this.transform.localScale.x == -1)
                {
                   love.transform.localScale = new Vector2(-0.5f, 0.5f);
                }
            }
            if (Instruction.text == "you are cute")
            {
                why.SetActive(false);
                love.SetActive(false);
                No.SetActive(false);
                Yes.SetActive(true);
                Yes.transform.localScale = new Vector2(0.5f, 0.5f);
                if (this.transform.localScale.x == -1)
                {
                    Yes.transform.localScale = new Vector2(-0.5f, 0.5f);
                }
            }
            if (Instruction.text == "are you hungry" )
            {
                why.SetActive(false);
                love.SetActive(false);
                Yes.SetActive(false);
                No.SetActive(true);
                No.transform.localScale = new Vector2(0.5f, 0.5f);
                if (this.transform.localScale.x == -1)
                {
                    No.transform.localScale = new Vector2(-0.5f, 0.5f);
                }
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.gameObject.tag=="door1")
        {
            SceneManager.LoadScene("Home");
        }
        if (collision.gameObject.tag == "door2")
        {
            SceneManager.LoadScene("Hall");
        }
        if (collision.gameObject.tag == "door3")
        {
            SceneManager.LoadScene("Home1");
        }
        if (collision.gameObject.tag == "door4")
        {
            SceneManager.LoadScene("Garden");
        }
    }

}
